<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>hello react</title>
    <style></style>
  </head>
  <body>
    <div id="test"></div>
    <!-- 引入react核心库 -->
    <script src="../js/react.development.js"></script>
    <!-- 引入react Dom库 用于支持 react操作dom-->
    <script src="../js/react-dom.development.js"></script>
    <!-- 引入babel 用于将 jsx 转为 js -->
    <script src="../js/babel.min.js"></script>

    <!-- 使用babel 转译jsx -->
    <script type="text/babel">
      class A extends React.Component {
        state = {
          carName: "奔驰",
        };
        changeCar = () => {
          this.setState({
            carName: "布加迪威龙",
          });
        };
        render() {
          return (
            <div>
              <div>A</div>
              <button onClick={this.changeCar}>换车</button>
              <B carName={this.state.carName} />
            </div>
          );
        }
      }
      class B extends React.Component {
        // 组件将要接收props,首次不调用
        UNSAFE_componentWillReceiveProps(props) {
          console.log(props);
          console.log("componentWillReceiveProps");
        }
        render() {
          return <div>B：{this.props.carName}</div>;
        }
      }
      ReactDOM.render(<A />, document.getElementById("test"));
    </script>
  </body>
</html>
